package pers.qianyu.service.impl;

import org.springframework.beans.factory.annotation.*;
import org.springframework.stereotype.*;
import pers.qianyu.dao.*;
import pers.qianyu.domain.*;
import pers.qianyu.service.*;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductDao productDao;

    @Override
    public Product findById(Integer pid) {
        return productDao.findById(pid).get();
    }

    @Override
    public void reduceInventory(Integer pid, int num) {
        Product product = productDao.findById(pid).get();
        if (product.getStock() < num) {
            throw new RuntimeException("库存不足");
        }
        int i = 1 / 0;
        product.setStock(product.getStock() - num);
        productDao.save(product);
    }
}
